import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  state: { //用于存放数据
    list: [],
    bannerList: [],
    total:0
  },
  mutations: { //用于存放同步方法
    setList(state, payload) {
      state.list = payload.list
      state.bannerList = payload.banner
      state.total=payload.total
    }
  },
  actions: { //用于存放异步方法
    async getList({
      commit
    }) { //commit触发同步方法
      const res = await axios.get('/api/list')
      commit('setList', res.data)
      console.log(res.data.list);
      console.log(res.data.banner);
    }, 
    async getTab({
      commit
    }) { //commit触发同步方法
      const res = await axios.get('/api/tab')
      commit('setList', res.data)
      console.log(res.data.list);
      console.log(res.data.banner);
    }
    
  },
  modules: { //用于拆分模块

  }
})